package com.glorysoft.knowlespda.ui.updatecount.view

import android.os.Bundle
import com.glorysoft.knowlespda.BR
import com.glorysoft.knowlespda.R
import com.glorysoft.knowlespda.base.BaseActivity
import com.glorysoft.knowlespda.databinding.ActivityUpdateCountBinding
import com.glorysoft.knowlespda.entity.ui.ToastMessageBean
import com.glorysoft.knowlespda.ui.updatecount.viewmodel.UpdateCountViewModel
import com.glorysoft.knowlespda.utils.FreeApi_DialogUtils
import kotlinx.android.synthetic.main.activity_update_count.*

/**
 * FileName: HomeActivity
 * Author: XJH
 * Date: 2021/7/12 17:19
 * Description:
 * History:
 */
class UpdateCountActivity : BaseActivity<UpdateCountViewModel, ActivityUpdateCountBinding>() {
    override fun layoutId(): Int {
        return R.layout.activity_update_count
    }

    override fun initVariableId(): Int {
        return BR.updateCountViewModel
    }

    override fun initView(savedInstanceState: Bundle?) {
        setTitle(this.getString(R.string.countupdate))

        initEdit(etMachineID, object : EditTextListener {
            override fun onTextChangeListener(s: String) {
                viewModel.getCountInfo(s)
            }

        })

        tvUpdate.setOnClickListener {
            if (etCount.text.toString().isEmpty()) {
                viewModel.defUI.toastEvent.value = ToastMessageBean(this.getString(R.string.please_enter_value), false)
                return@setOnClickListener
            }

            viewModel.updateCount(etCount.text.toString())
        }

    }

    override fun initData() {
        viewModel.defUI.startActivity.observe(this) {
            val tipDialog = FreeApi_DialogUtils.getConfirmDialog(this, this.getString(R.string.confirm), this.getString(R.string.operation_succeeded),this.getString(R.string.tips)) {
                finish()
            }
            tipDialog.show(this.supportFragmentManager, "DIALOG")
        }
    }
}